<?php
namespace app\common\taglib;
use think\template\TagLib;

/**
*自定义标签库 
*/
class UntilTag extends TagLib
{
	protected $tags = [
		'orderstatus' => ['attr'=> 'id,status,class' ,'close' => 0],
        'ordertype' => ['attr'=>'type' ,'close' => 0],
        'servicetype' => ['attr'=>'type' ,'close' => 0],
        'orderorigin' => ['attr'=>'type','close' => 0],
        'sexicon' => ['attr'=>'sex','close' => 0],
        'banner' => ['attr'=>'','close'=>0],
        'notice' => ['attr'=>'','close'=>0],
	];

	/**
	 * 订单状态
	 * !empty($tag['class'])订单列表页状态选择
	 * [tagOrderstatus description]
	 * @param  [type] $tag     [description]
	 * @param  [type] $content [description]
	 * @return [type]          [description]
	 */
	public function tagOrderstatus($tag,$content){
        $status = !empty($tag['status']) ? $tag['status'] : '6'; //订单状态
		$order_id = !empty($tag['id']) ? $tag['id'] : '0';//订单id
		$class = !empty($tag['class']) ? $tag['class'] : 'order-edit-status';//当前模式，默认是订单编辑模式
        $status = $this->autoBuildVar($status); //转化为变量形式
		$order_id = $this->autoBuildVar($order_id);

		$parseStr = '<?php $order_status = config("website.order_status");$status_selected = null; $order_id = '.$order_id.';';
		$parseStr .= '$order_status_list = "<select class=\''.$class.' form-control\' name=\'status\' style=\'width:auto;\'>";';
		$parseStr .= !empty($tag['class']) ? '$order_status_list .= "<option value=\'all\' selected>全部</option>";' : ' $status = '.$status.'; ';//是否显示全部情况判断
		$parseStr .= 'foreach($order_status as $key=>$value){
						if(isset($status))
							$status_selected = ($status == $key) ?  "selected" : " ";	
						
						$order_status_list .= "<option data-id=\'".$order_id."\' value=\'".$key."\' ".$status_selected.">".$value."</option>";
						}
						$order_status_list .= "</select>";					
						';
		$parseStr .= 'echo $order_status_list;';
		$parseStr .= '?>';
		return $parseStr;
	}

    /**
     * 订单类型
     * @param $tag
     * @param $content
     * @return string
     */
	public function tagOrdertype($tag,$content){
        $type = !empty($tag['type']) ? $tag['type'] : '';//订单类型
        $type = $this->autoBuildVar($type);

        $parseStr = '<?php $order_type = config("website.order_type"); $type_selected = null;';
        $parseStr .= !empty($tag['type']) ? '$type ='.$type.';' : '';//type赋值

        $parseStr .= '$order_type_list = "<select class=\'form-control\' name=\'type\' style=\'width:auto;\'>";';
        $parseStr .= 'foreach($order_type as $key=>$value){
                        if(isset($type)){
                            $type_selected = ($type == $key) ?  "selected" : " ";
                        }
                        $order_type_list .= "<option value=\'".$key."\' ".$type_selected.">".$value."</option>";
					  }
					  $order_type_list .= "</select>";
					  ';

        $parseStr .= 'echo $order_type_list;';
        $parseStr .= '?>';
        return $parseStr;
    }

    /**
     * 服务类型
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagServicetype($tag,$content){
        $type = !empty($tag['type']) ? $tag['type'] : '';//订单服务类型
        $type = $this->autoBuildVar($type);

        $parseStr = '<?php $service_type = config("website.service_type"); $type_selected = null;';
        $parseStr .= !empty($tag['type']) ? '$type ='.$type.';' : '';//type赋值

        $parseStr .= '$service_type_list = "<select class=\'form-control service_type\' name=\'service\' style=\'width:auto;\'>";';
        $parseStr .= 'foreach($service_type as $key=>$value){
                        if(isset($type)){
                            $type_selected = ($type == $key) ?  "selected" : " ";
                        }
                        $service_type_list .= "<option value=\'".$key."\' ".$type_selected.">".$value."</option>";
					  }
					  $service_type_list .= "</select>";
					  ';

        $parseStr .= 'echo $service_type_list;';
        $parseStr .= '?>';
        return $parseStr;
    }

    /**
     * @param $tag
     * @param $content
     * @return string
     */
    public function tagOrderorigin($tag,$content){
        $type = !empty($tag['type']) ? $tag['type'] : '';//订单来源
        $type = $this->autoBuildVar($type);

        $parseStr = '<?php $order_origin = config("website.order_origin"); $type_selected = null;';
        $parseStr .= !empty($tag['type']) ? '$type ='.$type.';' : '';//type赋值

        $parseStr .= '$order_origin_list = "<select class=\'form-control\' name=\'origin\' style=\'width:auto;\'>";';
        $parseStr .= 'foreach($order_origin as $key=>$value){
                        if(isset($type)){
                            $type_selected = ($type == $key) ?  "selected" : " ";
                        }
                        $order_origin_list .= "<option value=\'".$key."\' ".$type_selected.">".$value."</option>";
					  }
					  $order_origin_list .= "</select>";
					  ';

        $parseStr .= 'echo $order_origin_list;';
        $parseStr .= '?>';
        return $parseStr;
    }

    /**
     * 性别图片
     * @param $tag
     * @return string
     */
    public function tagSexicon($tag,$content){
        $sex = $tag['sex'];
        $sex = $this->autoBuildVar($sex);
        $parseStr = '<?php $pic = '.$sex.' == 1 ? "boy.jpg" : "girl.jpg";';
        $parseStr .= '$icon = "<img src=\'__ADMIN__/images/".$pic."\' style=\'max-height:30px;\'>";';
        $parseStr .= 'echo $icon; ?>';
        return $parseStr;
    }


}